/****** Objeto:  Table [GOOGLECODERS].[Clientes]    Fecha de la secuencia de comandos: 09/17/2011 21:12:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [GOOGLECODERS].[Compra](
	[IdCompra] [int]  Primary key identity(1,1),
	[Monto] [float] NOT NULL,
	[Fecha] [datetime] NOT NULL,
	[IdTarjeta] [int] NOT NULL,
	[IdBeneficiario] [int] NOT NULL,
	[IdPostNet] [int] NOT NULL
	
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF


ALTER TABLE [GOOGLECODERS].[Compra] ADD
	CONSTRAINT FK_Tarjeta FOREIGN KEY (IdTarjeta)
		REFERENCES [GOOGLECODERS].[Tarjetas] (IdTarjeta),
	CONSTRAINT FK_Beneficiario FOREIGN KEY (IdBeneficiario)
		REFERENCES [GOOGLECODERS].[Beneficiarios] (IdBeneficiario),
	CONSTRAINT FK_PostNet FOREIGN KEY (IdPostnet)
		REFERENCES [GOOGLECODERS].[Postnet] (IdPostnet);

SET IDENTITY_INSERT [GOOGLECODERS].[Compra] ON

INSERT INTO [GD2C2011].[GOOGLECODERS].[Compra]
           ([IdCompra] 
			,[Monto]
            ,[Fecha]
            ,[IdTarjeta]
            ,[IdBeneficiario]
            ,[IdPostNet])  
	
SELECT DISTINCT 
		COMPRA_CODIGO
		,COMPRA_MONTO
		,COMPRA_FECHA
      ,t.IdTarjeta
      ,b.IdBeneficiario
      ,[POSTNET_NRO_SERIE]
  FROM [GD2C2011].[gd_eschema].[Maestra] m
	INNER JOIN GOOGLECODERS.Tarjetas T ON	
		T.NumeroTarjeta = m.TARJETA_NRO
	INNER JOIN GOOGLECODERS.Beneficiarios b ON
		b.razonSocial = m.BENEFICIARIO_NOMBRE
WHERE CLIENTE_NOMBRE IS NOT NULL

SET IDENTITY_INSERT [GOOGLECODERS].[Compra] OFF


